package com.smart.six.locale.reloadablemessagesource;

import org.springframework.context.ApplicationContext;
import org.springframework.context.MessageSource;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.GregorianCalendar;
import java.util.Locale;

/**
 * 测试国际化信息格式化串
 *
 * @author junrui.wang
 * @create 2018/7/13
 */
public class TestReloadableMessageSource {
    public static void reload() throws InterruptedException {
        ApplicationContext ac = new ClassPathXmlApplicationContext("classpath:com/smart/six/locale/reloadablemessagesource/beans.xml");

        //无需分别加载不同语言，不同国家/地区的本地化资源，仅仅通过资源名就可以加载整套国际化信息资源文件。
        //无需显示使用MessageFormat操作国际化信息
        MessageSource ms = (MessageSource) ac.getBean("myMessageSource1");

        Object[] params = {"John", new GregorianCalendar().getTime()};

        int i = 0;

        while(true){
            System.out.println("===============" + i + "===============");
            i++;
            String s1 = ms.getMessage("common.common", params, Locale.US);

            System.out.println("us:" + s1);

            Thread.currentThread().sleep(20000);


        }
    }
}
